#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

struct Node
{
    int key, id;
};

bool operator < ( const Node &a, const Node &b )
{
    return a.key < b.key;
}

int down[ 1001 ][ 1001 ], map[ 1001 ][ 1001 ], sum[ 1001 ][ 1001 ], x[ 1001 ], y[ 1001 ];
Node xx[ 1001 ], yy[ 1001 ];

int main( )
{
    int n, m, r, i, j, k, maxn;
    while ( scanf("%d%d", &n, &r) != EOF )
    {
    memset( map, 0, sizeof( map ) );
    for ( i = 0; i < n; i++ )
    {
        scanf("%d%d", &xx[ i ].key, &yy[ i ].key);
        xx[ i ].id = yy[ i ].id = i;
    }
    sort( xx, xx + n );
    sort( yy, yy + n );
    for ( i = 0; i < n; i++ )
    {
        x[ xx[ i ].id ] = i;
        y[ yy[ i ].id ] = i;
    }
    for ( i = 0; i < n; i++ )
        map[ x[ i ] ][ y[ i ] ]++;
        for ( i = 0; i < n; i++ )
        {
            down[ 0 ][ i ] = 0;
        k = 0;
        while ( xx[ k ].key - xx[ 0 ].key <= r && k < n )
        down[ 0 ][ i ] += map[ k++ ][ i ];
            for ( j = 1; j < n; j++ )
        {
                down[ j ][ i ] = down[ j - 1 ][ i ] - map[ j - 1 ][ i ];
           while ( xx[ k ].key - xx[ j ].key <= r && k < n )
            down[ j ][ i ] += map[ k++ ][ i ];
        }
        }
        maxn = 0;
        for ( i = 0; i < n; i++ )
        {
        k = 0;
        sum[ i ][ 0 ] = 0;
        while ( yy[ k ].key - yy[ 0 ].key <= r && k < n )
                sum[ i ][ 0 ] += down[ i ][ k++ ];
        for ( j = 1; j < n; j++ )
        {
        sum[ i ][ j ] = sum[ i ][ j - 1 ] - down[ i ][ j - 1 ];
            while ( yy[ k ].key - yy[ j ].key <= r && k < n )
                       sum[ i ][ j ] += down[ i ][ k++ ];
        }
        }
    for ( i = 0; i < n; i++ )
    {
        for ( j = 0; j < n; j++ )
        {
            if ( maxn < sum[ i ][ j ] )
                maxn = sum[ i ][ j ];
        }
    }
        printf("%d\n", maxn);
    }
    return 0;
}
